
package verifica.plsdatabase;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;

public class ReadThroughFiles {

	public static void main (String [] args)throws Exception{
		
		
		 String inflow = "C:/Users/Alket/codeindigo/FlickrAPI/AllData";
		 File Folder = new File(inflow);
		 File files[];
		 files = Folder.listFiles();
		 Set<String>set = new HashSet<String>();
		
		try{
	        String line = "";

           if(files.length>1)
           {
            for(int i = 0;i<files.length; i++){
            	System.out.println("reading file"+i);
            	BufferedReader br = new BufferedReader(new FileReader(files[i]));
            	
            	
            	while((line = br.readLine())!= null){
            	String[] s = line.split("/t");
            	String username= s[0];
            	set.add(username);
            	
            	}br.close();
            }
           }
		}catch(Exception e){
			e.getMessage();
		}
		System.out.println(set.size());
		
	/*	List<FlickrUser> f = new ArrayList<FlickrUser>();
		List<FlickrUser> fuse = new ArrayList<FlickrUser>();
		
		FlickrUserMethods.loadFlickrUser(f, "flickruser.tsv");
		
		
		for(int i = 0; i < f.size(); i++){
			String user = FlickrUserMethods.find3PicUser(f,f.get(i).username );
				if(user !=null){
				    fuse.add(f.get(i));
			    }
		}
		for (int i = 0; i < fuse.size(); i++) {
			System.out.println("*****************"+fuse.get(i).toString());
		}
		Collections.sort(fuse);
		
		
		for (int i = 0; i < fuse.size(); i++) {
			System.out.println(fuse.get(i).username+", "+fuse.get(i).lon+", "+fuse.get(i).lat+", "+fuse.get(i).date);
		}
		
		List<PLSUser> pls = new ArrayList<PLSUser>();
		Map<Integer, List<PLSUser>> map = new HashMap<Integer, List<PLSUser>>();
		
		for (int i = 0; i < fuse.size(); i++) {
			pls = findPLSUser(fuse.get(i));
			map.put(i, pls);
		}
		for(int j:map.keySet()){
			for (int i = 0; i < map.get(j).size(); i++) {
				System.out.println(map.get(j).get(i).username+", "+map.get(j).get(i).tempo);
			}
		}
		}
		
	public static List<PLSUser> findPLSUser(FlickrUser f){
		List<PLSUser> plsuser = new ArrayList<PLSUser>();

		 String inflow = "C:/DATA/data/PLS";
		 File Folder = new File(inflow);
		 File files[];
		 files = Folder.listFiles();
		
		try{
	        String line = "";

           if(files.length>1)
           {
            for(int i = 0;i<files.length; i++){
             
               System.out.print("reading...");
               System.out.println(files[i].getName()+", number: "+i);
               String filefullname = files[i].getName();
               String filetimestamp = filefullname.substring(filefullname.indexOf("_")+1, filefullname.indexOf("."));
               System.out.println("***"+filetimestamp); 
               long ts = Long.parseLong(filetimestamp);
               long c = -1799763L;
               long ftsp = f.getFUTimestamp(f);
              
               if(ftsp < ts){
            	  
               BufferedReader br = new BufferedReader(new FileReader(files[i]));
              
                 while((line = br.readLine())!=null){
		      
				  String [] riga = line.split("\t");
				  
				  String username = riga[0];
				  int imsi = Integer.parseInt(riga[1]);
				  long celllac = Long.parseLong(riga[2]);
				  long time = Long.parseLong(riga[3]);
				    if(time == ts){
					  plsuser.add(new PLSUser(username, imsi, celllac,time));
				    }
				  }br.close();
              }
           //break;
           }
         }
		 }catch( Exception ex){
		    	ex.printStackTrace(); 
	  }
		return plsuser;
	}
	
	*/
	}
	
	}
	
	
